<template>
  <div>
    <el-descriptions v-loading="formLoading" :column="1" border label-width="230">
      <el-descriptions-item :label="t('studentPaper.fields.studentCode')">
        {{ processVo.studentCode }}
      </el-descriptions-item>
      <el-descriptions-item :label="t('studentPaper.fields.studentName')">
        {{ processVo.studentName }}
      </el-descriptions-item>
      <el-descriptions-item :label="t('studentPaper.fields.mentorName')">
        {{ processVo.mentorName }}
      </el-descriptions-item>
      <el-descriptions-item :label="t('studentPaper.fields.paperTitle')">
        {{ processVo.paperTitle }}
      </el-descriptions-item>
      <el-descriptions-item :label="t('studentPaper.fields.attachment')">
        <IMRUpload
          v-model="processVo.attachment"
          :file-type="['pdf']"
          :file-size="20"
          :limit="1"
          disabled
        />
      </el-descriptions-item>
      <el-descriptions-item :label="t('studentPaper.fields.paperType')">
        <dict-tag
          v-if="processVo.paperType"
          :type="DICT_TYPE.RESEARCH_PAPER_TYPE"
          :value="processVo.paperType"
        />
      </el-descriptions-item>
      <el-descriptions-item :label="t('studentPaper.fields.primaryAuthor')">
        {{ processVo.primaryAuthor }}
      </el-descriptions-item>
      <el-descriptions-item :label="t('studentPaper.fields.personalRanking')">
        <dict-tag
          v-if="processVo.personalRanking"
          :type="DICT_TYPE.RESEARCH_PERSONAL_RANKING"
          :value="processVo.personalRanking"
        />
      </el-descriptions-item>
      <el-descriptions-item
        v-if="processVo.personalRanking === '并列第一'"
        :label="t('studentPaper.fields.parallelCount')"
      >
        {{ t('studentPaper.inputTips.parallelCountPrefix') }}
        {{ processVo.parallelCount }}
        {{ t('studentPaper.inputTips.parallelCountSuffix') }}
      </el-descriptions-item>
      <el-descriptions-item
        v-if="processVo.personalRanking === '并列第一'"
        :label="t('studentPaper.fields.parallelRanking')"
      >
        {{ t('studentPaper.inputTips.parallelRankingPrefix') }}
        {{ processVo.parallelRanking }}
        {{ t('studentPaper.inputTips.parallelRankingSuffix') }}
      </el-descriptions-item>
      <el-descriptions-item :label="t('studentPaper.fields.casRanking')">
        <dict-tag
          v-if="processVo.casRanking"
          :type="DICT_TYPE.RESEARCH_USTC_RANKING"
          :value="processVo.casRanking"
        />
      </el-descriptions-item>
      <el-descriptions-item :label="t('studentPaper.fields.imrRanking')">
        <dict-tag
          v-if="processVo.imrRanking"
          :type="DICT_TYPE.RESEARCH_IMR_RANKING"
          :value="processVo.imrRanking"
        />
      </el-descriptions-item>
      <el-descriptions-item :label="t('studentPaper.fields.journalName')">
        {{ processVo.journalName }}
      </el-descriptions-item>
      <el-descriptions-item :label="t('studentPaper.fields.journalIssn')">
        {{ processVo.journalIssn }}
      </el-descriptions-item>
      <el-descriptions-item
        label-class-name="negative-warning-label"
        class-name="negative-warning-content"
        v-if="processVo.negative"
        :label="t('studentPaper.view.warning')"
      >
        <el-alert type="error" :closable="false">{{ processVo.negativeMessage }}</el-alert>
      </el-descriptions-item>
      <el-descriptions-item :label="t('studentPaper.fields.journalDistrict')">
        {{ processVo.journalDistrict }}
      </el-descriptions-item>
      <!-- 影响因子 暂时隐藏 -->
      <el-descriptions-item v-if="false" :label="t('studentPaper.fields.journalImpactFactor')">
        {{ processVo.journalImpactFactor }}
      </el-descriptions-item>
      <el-descriptions-item :label="t('studentPaper.fields.retrievalStatus')">
        <dict-tag
          v-if="processVo.retrievalStatus"
          :type="DICT_TYPE.RESEARCH_RETRIEVAL_STATUS"
          :value="processVo.retrievalStatus"
        />
      </el-descriptions-item>
      <el-descriptions-item :label="t('studentPaper.fields.publicationStatus')">
        <dict-tag
          v-if="processVo.publicationStatus"
          :type="DICT_TYPE.RESEARCH_PUBLICATION_STATUS"
          :value="processVo.publicationStatus"
        />
      </el-descriptions-item>
      <el-descriptions-item
        v-if="processVo.publicationStatus === '已接收'"
        :label="t('studentPaper.fields.acceptanceLetter')"
      >
        <IMRUpload
          v-model="processVo.acceptanceLetter"
          :file-type="['pdf']"
          :file-size="20"
          :limit="1"
          disabled
        />
      </el-descriptions-item>
      <el-descriptions-item
        v-if="processVo.publicationStatus === '已接收'"
        :label="t('studentPaper.fields.receiveTime')"
      >
        {{ processVo.receiveTime ? formatDate(processVo.receiveTime, 'YYYY-MM-DD') : '' }}
      </el-descriptions-item>
      <el-descriptions-item
        v-if="processVo.publicationStatus === '已在线'"
        :label="t('studentPaper.fields.retrievalNumber')"
      >
        {{ processVo.retrievalNumber }}
      </el-descriptions-item>
      <el-descriptions-item
        v-if="processVo.publicationStatus === '已在线'"
        :label="t('studentPaper.fields.onlineTime')"
      >
        {{ processVo.onlineTime ? formatDate(processVo.onlineTime, 'YYYY-MM-DD') : '' }}
      </el-descriptions-item>
      <el-descriptions-item
        v-if="processVo.publicationStatus === '已发表'"
        :label="t('studentPaper.fields.publicationNumber')"
      >
        {{ processVo.publicationNumber }}
      </el-descriptions-item>
      <el-descriptions-item
        v-if="processVo.publicationStatus === '已发表'"
        :label="t('studentPaper.fields.publishTime')"
      >
        {{ processVo.publishTime ? formatDate(processVo.publishTime, 'YYYY-MM-DD') : '' }}
      </el-descriptions-item>
      <el-descriptions-item :label="t('studentPaper.fields.remark')">
        {{ processVo.remark }}
      </el-descriptions-item>
    </el-descriptions>
  </div>
</template>

<script setup lang="ts">
import { ProcessVoApi } from '@/api/bpm/processvo'
import { DICT_TYPE } from '@/utils/dict'
import IMRUpload from '@/components/IMRUpload/index.vue'
import { formatDate } from '@/utils/formatTime'
import { StudentPaperVO } from '@/api/core/studentpaper'
import { propTypes } from '@/utils/propTypes'

defineOptions({ name: 'BpmPaperDetail' })

const props = defineProps({
  id: propTypes.string.def(undefined)
})

const { query } = useRoute() // 查询参数
const { t } = useI18n() // 国际化

const queryId = query.id as unknown as string // 从 URL 传递过来的 流程实例ID

const processVo = ref<StudentPaperVO>({} as StudentPaperVO)

const formLoading = ref(false)

onMounted(async () => {
  formLoading.value = true
  const response = await ProcessVoApi.getProcessVoByProcessInstanceId(props.id || queryId)
  formLoading.value = false
  processVo.value = JSON.parse(response.vo)
})
</script>
